package com.agree.util.excel.handlers.mapping.params;

import com.agree.util.excel.entity.TableInfo;

import java.io.*;
import java.util.ArrayList;
import java.util.List;

/**
 * Created by wangmu on 2017/12/8.
 */
public class FileGetParamsHandler implements GetParamsHandler {

    @Override
    public List<String> getParams(TableInfo tableInfo, String... path) throws IOException {
        if(path == null || path[0]==null) {
            return null;
        }
        File file = new File(path[0],tableInfo.getName()+".txt");
        if(!file.exists()) {
            throw new FileNotFoundException("请添加相应文件:"+file.getAbsolutePath());
        }

        List<String> params = new ArrayList<>();
        BufferedReader reader = new BufferedReader(new FileReader(file));
        String temp = null;
        while ((temp = reader.readLine()) != null) {
            String trim = temp.trim();
            if(trim != null && !trim.equals("")) {
                params.add(trim.toLowerCase());
            }
        }
        reader.close();
        return params;
    }
}
